/**
 * @(#) MarksApprovalServiceImpl.java
 * Copyright (c) 2011 EdRP, Dayalbagh Educational Institute.
 * All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * Redistributions of source code must retain the above copyright
 * notice, this  list of conditions and the following disclaimer.
 *
 * Redistribution in binary form must reproducuce the above copyright
 * notice, this list of conditions and the following disclaimer in
 * the documentation and/or other materials provided with the
 * distribution.
 *
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL ETRG OR ITS CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Contributors: Members of EdRP, Dayalbagh Educational Institute
 */
package in.ac.dei.edrp.cms.daoimpl.coursemarksapproval;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import in.ac.dei.edrp.cms.dao.coursemarksapproval.MarksApprovalService;
import in.ac.dei.edrp.cms.daoimpl.universityreservation.UniversityReservationServiceImpl;
import in.ac.dei.edrp.cms.domain.coursemarksapproval.MarksApprovalInfo;

/**
 * this is Server side Implementation class for Marks Approval
 * 
 * @version 1.0 16 MAR 2011
 * @author MOHD AMIR
 */
public class MarksApprovalServiceImpl extends SqlMapClientDaoSupport implements
		MarksApprovalService {

	/** Creating object of Logger for log Maintenance */
	private static Logger logObj = Logger
			.getLogger(UniversityReservationServiceImpl.class);

	/**
	 * This method retrieves Approval Details from database
	 *
	 * @param marksApprovalInfo, object of bean class MarksApprovalInfo
	 * @return approvalDetails containing Approval Details
	 */
	@SuppressWarnings("unchecked")
	public List<MarksApprovalInfo> getApprovalDetails(
			MarksApprovalInfo marksApprovalInfo) {
		List<MarksApprovalInfo> approvalDetails = new ArrayList<MarksApprovalInfo>();
		try {
			approvalDetails = getSqlMapClientTemplate().queryForList(
					"marksApproval.getMarksApprovalDetails", marksApprovalInfo);
		} catch (Exception e) {
			logObj.error(e.getMessage());
		}
		return approvalDetails;
	}

	/**
	 * This method retrieves Course Details from database
	 *
	 * @param marksApprovalInfo, object of bean class MarksApprovalInfo
	 * @return courseList containing Course Details
	 */
	@SuppressWarnings("unchecked")
	public List<MarksApprovalInfo> getCourseList(
			MarksApprovalInfo marksApprovalInfo) {
		List<MarksApprovalInfo> courseList = new ArrayList<MarksApprovalInfo>();
		try {
			courseList = getSqlMapClientTemplate().queryForList(
					"marksApproval.getCourseList", marksApprovalInfo);
		} catch (Exception e) {
			logObj.error(e.getMessage());
		}
		return courseList;
	}

	/**
	 * This method retrieves Employee Details from database
	 *
	 * @param marksApprovalInfo, object of bean class MarksApprovalInfo
	 * @return employeeList containing Employee Details
	 */
	@SuppressWarnings("unchecked")
	public List<MarksApprovalInfo> getEmployeeList(
			MarksApprovalInfo marksApprovalInfo) {
		List<MarksApprovalInfo> employeeList = new ArrayList<MarksApprovalInfo>();
		try {
			employeeList = getSqlMapClientTemplate().queryForList(
					"marksApproval.getEmployeeList", marksApprovalInfo);
		} catch (Exception e) {
			logObj.error(e.getMessage());
		}
		return employeeList;
	}

	/**
	 * This method insert the marks approval details into database
	 *
	 * @param marksApprovalInfo, object of bean class MarksApprovalInfo
	 * @return value of type boolean show whether the record are inserted or not
	 */
	public Boolean setApprovalDetails(MarksApprovalInfo marksApprovalInfo) {
		try {
			getSqlMapClientTemplate().insert("marksApproval.setMarksApprovalDetails", marksApprovalInfo);
			return true;
		} catch (Exception e) {
			logObj.error(e.getMessage());
			return false;
		}
	}

	/**
	 * This method get duplicate record count from database 
	 *
	 * @param registrationNo, registration Number
	 * @return count,Number of record found
	 */
	 @SuppressWarnings("unchecked")
	public int getDuplicateCount(
			MarksApprovalInfo marksApprovalInfo) {
		List<MarksApprovalInfo> countList = new ArrayList<MarksApprovalInfo>();
		int count=1;
		try {
			countList = getSqlMapClientTemplate().queryForList("marksApproval.getDuplicateRecordCount", marksApprovalInfo);
			count= countList.get(0).getCount();
		} catch (Exception e) {
			logObj.error(e.getMessage());
		}
		return count;
	}

	/**
	 * This method delete Approval Details from database
	 *
	 * @param marksApprovalInfo, object of bean class MarksApprovalInfo
	 * @return count,no of record deleted
	 */
	public int deleteApprovalDetails(MarksApprovalInfo marksApprovalInfo) {
		int count=0;
		try {
			count = getSqlMapClientTemplate().delete("marksApproval.deleteApprovalDetails", marksApprovalInfo);
		} catch (Exception e) {
			logObj.error(e.getMessage());
		}
		return count;
	}

	/**
	 * This method update Approval Details into database
	 *
	 * @param marksApprovalInfo, object of bean class MarksApprovalInfo
	 * @return count,no of record updated
	 */
	public int updateApprovalDetails(MarksApprovalInfo marksApprovalInfo) {
		int count=0;
		try {
			count = getSqlMapClientTemplate().update("marksApproval.updateApprovalDetails", marksApprovalInfo);
		} catch (Exception e) {
			logObj.error(e.getMessage());
		}
		return count;
	}
}